//
//  addAddressViewController.swift
//  二次源
//
//  Created by 李建文 on 2016/11/22.
//  Copyright © 2016年 二次源. All rights reserved.
//

import UIKit

class addAddressViewController: UIViewController,UITextFieldDelegate{

    //姓名
    @IBOutlet weak var name: UITextField!
    
    //电话
    @IBOutlet weak var telephone: UITextField!
    
    //地址
    @IBOutlet weak var address: UITextField!
    
    //男士
    @IBOutlet weak var boy: UIButton!
    
    //性别
    private var sex:String = "1"
    
    //女士
    @IBOutlet weak var girl: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "添加地址"
        //是输入框获得焦点
        self.name.becomeFirstResponder()
        self.telephone.becomeFirstResponder()
        self.address.becomeFirstResponder()
        //是输入框失去焦点
        self.name.resignFirstResponder()
        self.telephone.resignFirstResponder()
        self.address.resignFirstResponder()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //点击男士
    @IBAction func didBoy(_ sender: AnyObject) {
        self.boy.setBackgroundImage(UIImage(named: "方格_选中"), for:.normal)
        self.girl.setBackgroundImage(UIImage(named: "195-方块未选"), for:.normal)
        sex = "1"
    }
    
    //点击女士
    @IBAction func didGirl(_ sender: AnyObject) {
        self.girl.setBackgroundImage(UIImage(named:"方格_选中"),for:.normal)
        self.boy.setBackgroundImage(UIImage(named:"195-方块未选"),for:.normal)
        sex = "0"
    }
 
    //点击完成
    @IBAction func didFinish(_ sender: AnyObject) {
        if (!(self.name.text != nil) && !(self.telephone.text != nil) && !(self.address.text != nil)) {
            let alertController = UIAlertController(title: "系统提示",
                                                    message: "您输入的信息不完整", preferredStyle: .alert)
            let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
            let okAction = UIAlertAction(title: "好的", style: .default, handler: {
                action in
                print("点击了确定")
                self.name.text=""
                self.address.text=""
                self.telephone.text=""
            })
            alertController.addAction(cancelAction)
            alertController.addAction(okAction)
            self.present(alertController, animated: true, completion: nil)
        }
        print("点击完成")
            let net: Net = Net()
            let url = "/addAddress?uid=1&"+"adname="+self.name.text!+"&adphone="+self.telephone.text!+"&address="+self.address.text!+"&adsex="+self.sex
            net.addUrl(url: url)
            net.sendPostWithParam()
            print(net.data)
        
        }
    
}
